from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-06 14:04:07.874809
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 06, Jul, 2022
Time: 14:04:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7080
Nobs: 709.000 HQIC: -50.0636
Log likelihood: 8862.63 FPE: 1.44702e-22
AIC: -50.2874 Det(Omega_mle): 1.27565e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298572 0.057471 5.195 0.000
L1.Burgenland 0.105782 0.037748 2.802 0.005
L1.Kärnten -0.109582 0.019997 -5.480 0.000
L1.Niederösterreich 0.210250 0.078866 2.666 0.008
L1.Oberösterreich 0.106375 0.077202 1.378 0.168
L1.Salzburg 0.257202 0.040372 6.371 0.000
L1.Steiermark 0.044823 0.052596 0.852 0.394
L1.Tirol 0.109980 0.042695 2.576 0.010
L1.Vorarlberg -0.060904 0.036940 -1.649 0.099
L1.Wien 0.042989 0.068268 0.630 0.529
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048552 0.120359 0.403 0.687
L1.Burgenland -0.034117 0.079055 -0.432 0.666
L1.Kärnten 0.041177 0.041879 0.983 0.325
L1.Niederösterreich -0.167979 0.165167 -1.017 0.309
L1.Oberösterreich 0.424078 0.161682 2.623 0.009
L1.Salzburg 0.288355 0.084550 3.410 0.001
L1.Steiermark 0.101170 0.110150 0.918 0.358
L1.Tirol 0.318733 0.089414 3.565 0.000
L1.Vorarlberg 0.028488 0.077361 0.368 0.713
L1.Wien -0.041022 0.142971 -0.287 0.774
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187604 0.029402 6.381 0.000
L1.Burgenland 0.090290 0.019312 4.675 0.000
L1.Kärnten -0.008009 0.010230 -0.783 0.434
L1.Niederösterreich 0.265342 0.040347 6.576 0.000
L1.Oberösterreich 0.137620 0.039496 3.484 0.000
L1.Salzburg 0.045987 0.020654 2.227 0.026
L1.Steiermark 0.019904 0.026907 0.740 0.459
L1.Tirol 0.091615 0.021842 4.194 0.000
L1.Vorarlberg 0.057101 0.018898 3.022 0.003
L1.Wien 0.113764 0.034925 3.257 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111700 0.029916 3.734 0.000
L1.Burgenland 0.045104 0.019650 2.295 0.022
L1.Kärnten -0.013753 0.010409 -1.321 0.186
L1.Niederösterreich 0.191594 0.041054 4.667 0.000
L1.Oberösterreich 0.303135 0.040187 7.543 0.000
L1.Salzburg 0.108304 0.021016 5.153 0.000
L1.Steiermark 0.104657 0.027379 3.823 0.000
L1.Tirol 0.104009 0.022225 4.680 0.000
L1.Vorarlberg 0.066591 0.019229 3.463 0.001
L1.Wien -0.021971 0.035537 -0.618 0.536
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134505 0.054553 2.466 0.014
L1.Burgenland -0.051829 0.035832 -1.446 0.148
L1.Kärnten -0.044340 0.018982 -2.336 0.019
L1.Niederösterreich 0.156794 0.074862 2.094 0.036
L1.Oberösterreich 0.139758 0.073282 1.907 0.057
L1.Salzburg 0.286706 0.038322 7.481 0.000
L1.Steiermark 0.047629 0.049925 0.954 0.340
L1.Tirol 0.166915 0.040527 4.119 0.000
L1.Vorarlberg 0.092795 0.035064 2.646 0.008
L1.Wien 0.073401 0.064802 1.133 0.257
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055178 0.043398 1.271 0.204
L1.Burgenland 0.037377 0.028505 1.311 0.190
L1.Kärnten 0.051028 0.015100 3.379 0.001
L1.Niederösterreich 0.217718 0.059554 3.656 0.000
L1.Oberösterreich 0.294971 0.058297 5.060 0.000
L1.Salzburg 0.047958 0.030486 1.573 0.116
L1.Steiermark 0.001369 0.039716 0.034 0.972
L1.Tirol 0.141078 0.032240 4.376 0.000
L1.Vorarlberg 0.072915 0.027894 2.614 0.009
L1.Wien 0.081290 0.051551 1.577 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175324 0.051897 3.378 0.001
L1.Burgenland -0.002750 0.034087 -0.081 0.936
L1.Kärnten -0.063026 0.018058 -3.490 0.000
L1.Niederösterreich -0.081724 0.071217 -1.148 0.251
L1.Oberösterreich 0.195102 0.069715 2.799 0.005
L1.Salzburg 0.056706 0.036457 1.555 0.120
L1.Steiermark 0.236129 0.047495 4.972 0.000
L1.Tirol 0.497676 0.038554 12.909 0.000
L1.Vorarlberg 0.044040 0.033357 1.320 0.187
L1.Wien -0.054883 0.061647 -0.890 0.373
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170390 0.059198 2.878 0.004
L1.Burgenland -0.012230 0.038883 -0.315 0.753
L1.Kärnten 0.063751 0.020598 3.095 0.002
L1.Niederösterreich 0.208257 0.081236 2.564 0.010
L1.Oberösterreich -0.075948 0.079522 -0.955 0.340
L1.Salzburg 0.212936 0.041585 5.120 0.000
L1.Steiermark 0.124808 0.054176 2.304 0.021
L1.Tirol 0.068206 0.043978 1.551 0.121
L1.Vorarlberg 0.118381 0.038050 3.111 0.002
L1.Wien 0.123804 0.070319 1.761 0.078
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.363193 0.034219 10.614 0.000
L1.Burgenland 0.007557 0.022476 0.336 0.737
L1.Kärnten -0.023670 0.011907 -1.988 0.047
L1.Niederösterreich 0.215942 0.046958 4.599 0.000
L1.Oberösterreich 0.204495 0.045967 4.449 0.000
L1.Salzburg 0.043397 0.024038 1.805 0.071
L1.Steiermark -0.014348 0.031316 -0.458 0.647
L1.Tirol 0.105565 0.025421 4.153 0.000
L1.Vorarlberg 0.070265 0.021994 3.195 0.001
L1.Wien 0.029950 0.040648 0.737 0.461
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037270 0.137853 0.194850 0.155396 0.115774 0.102414 0.058499 0.216315
Kärnten 0.037270 1.000000 -0.015674 0.134125 0.055948 0.095003 0.435602 -0.053535 0.093424
Niederösterreich 0.137853 -0.015674 1.000000 0.334620 0.141067 0.294045 0.092026 0.177129 0.311843
Oberösterreich 0.194850 0.134125 0.334620 1.000000 0.226884 0.325024 0.176396 0.164330 0.263042
Salzburg 0.155396 0.055948 0.141067 0.226884 1.000000 0.137872 0.116585 0.138108 0.129718
Steiermark 0.115774 0.095003 0.294045 0.325024 0.137872 1.000000 0.145380 0.130899 0.071895
Tirol 0.102414 0.435602 0.092026 0.176396 0.116585 0.145380 1.000000 0.111219 0.141924
Vorarlberg 0.058499 -0.053535 0.177129 0.164330 0.138108 0.130899 0.111219 1.000000 0.001027
Wien 0.216315 0.093424 0.311843 0.263042 0.129718 0.071895 0.141924 0.001027 1.000000